"""
列级的增删改查
"""
import numpy as np
import pandas as pd

data = {'one':pd.Series([1,2,3],index=['a','b','c']),
        'two':pd.Series([1,2,3,4],index=['a','b','c','d']),
        'three':pd.Series([1,3,4],index=['a','c','d'])}
df = pd.DataFrame(data)
# print(df)
# 访问某一列：直接索引 df[列名]
# 访问多列：不能切片，使用掩码
# print(df['one'])
# print(df[['one','two']])
# print(df[df.columns[:2]])


# 列的添加 df[列名] = 值
# df['four'] = ['1','2','3','4']
# 如果列的值为Series时，需要给出原df的index
df['four'] = pd.Series(['1','2','3','4'],index=['a','b','c','d'])
# print(df)

# 列的删除 del pop 一次只能删除一列 drop 删除多列
# del df['four']
# print(df)
#
# df.pop('three')
# print(df)
# inplace：是否修改原始数据，inplace:False不修改，True修改
df.drop(['one','two'],axis=1,inplace=True)
print(df)

ary = np.array([[0.3,0.6,0.1],
                [0.7,0.89,0.12],
                [0.45,0.6,0.01]])
ary[ary > 0.5] = 666
ary[ary <= 0.5] = 0
print(ary)



